/***     
 * 查找同数值的牌
 */

var _ = require('../Underscore');
var FindCardTool = require('./FindCardTool');
var CardTool = require('./../CardTool');
var FindSameCardTool = module.exports = {};

/***
 * 获得相同牌数量
 * _cardInfoList:[{"cardId":64,"type":2,"value":12},{"cardId":22,"type":2,"value":9}]//牌信息
 * sameNumber:相同牌个数
 * return {
        isFind: true,
        findGroup: [{"cardId":64,"type":2,"value":12}],
        otherGroup:  [{"cardId":64,"type":2,"value":12}]
    };
 */
FindSameCardTool.getResult = function(_cardInfoList, sameNumber) {
    var tmpCards = this.check(_cardInfoList);
    var result = FindCardTool.getResult(tmpCards, function(_group) {
        return sameNumber == _.size(_group);
    }, function(_group) {
        return sameNumber != _.size(_group);
    });

    // CardTool.LogResult(result, ("查找" + sameNumber + "同结果"))
    return result;
};

FindSameCardTool.check = function(_cardInfoList) {
    var tmpCards = {};
    var size = _.size(_cardInfoList);
    for (var i = 0; i < size; ++i) {
        var cardInfo = _cardInfoList[i];
        var value = cardInfo.value;
        if (null == tmpCards[value]) {
            tmpCards[value] = [];
        }
        tmpCards[value].push(cardInfo);
    }
    return tmpCards;
};